﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RFIDSystem.Controllers;
using RFIDSystem.IServices;
using RFIDSystem.Model;
using RFIDSystem.Model.Models;
using RFIDSystem.Model.ViewModels;
using RFIDSystem.Services;

namespace RFIDSystem.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Permissions.Name)]
    public class ElectronicFenceController : BaseApiController
    {
        public IElectronicFenceServices _electronicFenceServices;

        public ElectronicFenceController(IElectronicFenceServices electronicFenceServices)
        {
            _electronicFenceServices = electronicFenceServices;
        }
        [HttpGet]
        public async Task<MessageModel<List<ElectronicFence>>> GetElectronicFences()
        {
            var rs = await _electronicFenceServices.GetElectronicFences();
            return new MessageModel<List<ElectronicFence>>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        [HttpGet]
        public async Task<MessageModel<List<ElectronicFence>>> GetMyElectronicFences()
        {
            var rs = await _electronicFenceServices.GetMyElectronicFences();
            return new MessageModel<List<ElectronicFence>>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        [HttpPost]
        public async Task<MessageModel<bool>> AddElectronicFence([FromBody] ElectronicFence input)
        {
            var rs = await _electronicFenceServices.AddElectronicFence(input);
            return new MessageModel<bool>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        [HttpPost]
        public async Task<MessageModel<bool>> EditElectronicFence([FromBody] ElectronicFence input)
        {
            var rs = await _electronicFenceServices.EditElectronicFence(input);
            return new MessageModel<bool>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        [HttpDelete]
        public async Task<MessageModel<bool>> DelElectronicFence(string id)
        {
            var rs = await _electronicFenceServices.DelElectronicFence(id);
            return new MessageModel<bool>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
    }
}
